package com.example.service;

import com.example.dao.UserDao;
import com.example.entity.User;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class UserService {

    @Autowired
    UserDao userDao;

    public User getUserById(int id){
        return userDao.getUserById(id);
    }

    public List<User> getUsers(){
        return userDao.getUsers();
    }

    public void saveUser(User user){
        if(user.getId() == 0){
            userDao.saveUser(user);
        }else{
            userDao.updateUser(user);
        }
    }

    public void deleteUser(int id){
        userDao.deleteUser(id);
    }

}
